package com.thundersoft.pickcolor.utils;

public class ColorUtils {
    /**
     * 16进制转GRB颜色值
     */
    public static int[] toRGB(String hex) {
        int color = Integer.parseInt(hex.replace("#", ""), 16);
        int red = (color & 0xff0000) >> 16;
        int green = (color & 0x00ff00) >> 8;
        int blue = (color & 0x0000ff);
        int[] rgb = {red, green, blue};
        return rgb;
    }

    /**
     * GRB转16进制颜色值
     */
    public static String toHex(int red, int green, int blue){
        String hr = Integer.toHexString(red);
        String hg = Integer.toHexString(green);
        String hb = Integer.toHexString(blue);
        if(hr.length()<2){
            hr = ""+"0"+hr;
        }
        if(hg.length()<2){
            hg = ""+"0"+hg;
        }
        if(hb.length()<2){
            hb = ""+"0"+hb;
        }
        return "#"+hr + hg + hb;
    }
}
